<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // const name = '解构赋值'


    // 对象解构
    const obj = { name: '小明', age: 22 }

    // const { name, age } = obj
    // const name = obj.name
    // const age = obj.age
    

    // 修改变量名称
    // const { name: name1, age } = obj
    // const name1 = obj.name
    // const age = obj.age
    // console.log(name1, age)

    // 默认值
    // const { name: name1 = '111', age, sex = '男' } = obj
    // const name1 = obj.name || '111'
    // const age = obj.age
    // const sex = obj.sex || '男'
    // console.log(sex)

    // 剩余参数
    // const { a, age, ...other } = { name: '小明', age: 22, sex: 1, a: 'aaa', b: 'BBB' }
    // const a = obj.a
    // const age = obj.age
    // const other = {
    //   name: obj.name,
    //   sex: obj.sex,
    //   b: obj.b
    // }
    // console.log(a, age, other)

    // 嵌套对象
    const { child: { child: { name: name1 } } } = {
      name: 'aa',
      child: {
        name: 'bb',
        child: {
          name: 'cc'
        }
      }
    }
    // const name = obj.child.child.name
    console.log(name1)
  </script>
</body>
</html>